﻿using Nop.Core.Domain.Logistics;
using System.Data.Entity.ModelConfiguration;

namespace Nop.Data.Mapping.Logistics
{
    public class DistrictMap : EntityTypeConfiguration<District>
    {
        public DistrictMap()
        {
            this.ToTable("LogisticsDistrict");
            this.HasKey(d => d.Id);

            this.Property(d => d.Name)
                .IsRequired()
                .HasMaxLength(1000);

            this.Property(d => d.Code)
                .IsRequired()
                .HasMaxLength(10);

            this.Property(d => d.CountryCode)
                .IsRequired()
                .HasMaxLength(5);

            this.Property(d => d.DisplayOrder)
                .IsRequired();

            this.HasRequired(d => d.StateProvince)
                .WithMany()
                .HasForeignKey(d => d.StateProvinceId);

            this.HasRequired(d => d.Region)
                .WithMany()
                .HasForeignKey(d => d.RegionId);

            this.HasMany(d => d.Zones)
                .WithRequired(d => d.District)
                .HasForeignKey(d => d.DistrictId);
        }
    }
}
